<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page session="true"%>
<%@page import="com.webapp.model.User"%>
<%@page import="com.webapp.model.Application"%>
<%@page import="java.util.ArrayList" %>
<% 
	User user = (User)session.getAttribute("UserObject");
	if(user != null)
		System.out.println(user.getUserName());
	
	ArrayList apps = (ArrayList)session.getAttribute("Table");

%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GARS - Table of Applications</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<style>
	body { font-size: 95%; font-family: 'Open Sans'; padding:0; margin:0; background-color:#fff;}
	h1 { padding:0; margin:0; }
	h2 { padding:0; margin:0; }
	.sign_on_btn { background-color: #CC0000; color: #fff; border: 1px solid #990000; padding: 5px; cursor:pointer!important;}
	.sign_on_btn:hover { background-color:red; }
	.txtbox { background-color:#fff; border: 1px solid #ccc; width: 200px; }<br />
	.txtbox:focus { border: 1px soild #CC0000; }
	a { color: blue; }
	#top_of_site { padding: 5px;color: #333; background-color: #333; color:#fff; border: 1px solid #000;}
	#top_of_site h1 { padding:0; margin:0; font-size: 90%; }
	#wrapper { padding: 15px; }
	#login { width: 300px; margin: 0px auto 0px auto; padding: 10px;background-color: #333; color:#fff; border: 1px solid #000; }
	#info_bar { text-align:right; }
	#menu_container { width: 560px; margin: 30px auto 0px auto;  overflow:auto;}
	#behaviorcontainer { float:left; width: 400px; overflow:auto; }
	#extra_info { width: 560px; margin: 30px auto 0px auto;}
	#menu_container a { text-decoration: none; color: #fff; }
	#logout { float:left; background-color:#f2f2f2; border: 1px solid #ccc; color:#333; width: 100px; padding: 59px 15px 59px 15px; margin: 5px; }
	#viewTable { background-color:#0066CC; border: 1px solid #0066FF; width: 350px; padding: 20px; margin: 5px; }
	#submitApp { background-color:#B22222; border: 1px solid #990000; width: 350px; padding: 20px; margin: 5px; } 
	#apptable td { padding: 5px; }
	.even { background-color:#fff; padding:10px; }
	.odd { background-color:#ccc; padding:10px;}
		.error { display:none; color:red; }
			.btn { background-color: #CC0000; color: #fff; border: 1px solid #990000; padding: 5px; cursor:pointer!important;}
			.btn:hover { background-color:red; }
</style>
<script type="text/javascript" src="https://www.google.com/jsapi?key=INSERT-YOUR-KEY"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script language="Javascript" type="text/javascript">
    		//<![CDATA[
			google.load("jquery", "1.6.4", {uncompressed:true});
			google.load("jqueryui", "1.8.16", {uncompressed:true});			
    		function OnLoad() {
				$(document).ready(function() {
					
					$.getQuery = function( query ) {
						query = query.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
						var expr = "[\\?&]"+query+"=([^&#]*)";
						var regex = new RegExp( expr );
						var results = regex.exec( window.location.href );
						if( results != null ) {
							return results[1];
							return decodeURIComponent(results[1].replace(/\+/g, " "));
						} 
					};
					
					var query = $.getQuery('edit');
					if(query != "" && query != null) {
						$('.error').slideDown('fast', function() {
							$('.error').text("Updated Application was Successful! ");
						});
					}
					
					if(query == "added") {
						$('.error').slideDown('fast', function() {
							$('.error').text("Application Added! ");
						});
					}
					
					if(query == "updated") {
						$('.error').slideDown('fast', function() {
							$('.error').text("Application Updated!");
						});
					} 
					
					if(query == "empty_search"){
						$('.error').slideDown('fast', function() {
							$('.error').text("No Result Found.");
						});
					}
				});
			}
    		
    		google.setOnLoadCallback(OnLoad);
    		//]]>
    	</script>
</head>

<body>
		<div id="top_of_site">
    		<h1>Graduate Application Review System (GARS) </h1>
    	</div>
	<div id="wrapper">
    	<form name="return" action="homepage.jsp" method="get">
					<!-- Returns to the previous page, which would be the view table page.-->
					<input type="submit" value="Goto Hompage" class="btn">
				</form>
    	<div id="info_bar">
        	<p style="padding:0; margin:0;">Welcome, <strong><%= user.getUserName() %></strong>! You are a <strong><%= user.getType()  %></strong> member! </p>
            <p> You have <strong><%= user.getReviews()%></strong> reviews waiting to be reviewed! <br/><a href="ViewUserApp.do">Review Now!</a></p>
        </div>
        
      <div id="content">
        <!-- this of course will end the JSP include page for the top of website because only content will change-->
        	<h4 class="error">&nbsp</h4>
    		<h2>Table of Applications</h2><br/>
            
            <div id="search" align="right">
            	<form action="Search.do" method="get">
                	<table>
                    	<tr>
                    		<td>Student's Name or E-mail: <input type="text" class="txtbox" name="search" id="searchID" />&nbsp;<input type="submit" id="searchBtn" value="Search" /></td>
                        </tr>
                    </table>
                </form>
            </div>
            
            <div id="sort" align="right">
            	<form action="Sort.do" method="get">
            		<table>
            			<tr>
            				<td>
            				Sort by:
            				<select name="sort_list1">
            					<option value="none">None</option>
            					<option value="first_name">First Name</option>
            					<option value="last_name">Last Name</option>
            					<option value="e-mail">E-mail</option>
            					<option value="research_area">Research Area</option>
            					<option value="undergraduate_school">Undergraduate School</option>
            					<option value="gpa">GPA</option>
            				</select>
            				
            				<select name="sort_list2">
            					<option value="none">None</option>
            					<option value="first_name">First Name</option>
            					<option value="last_name">Last Name</option>
            					<option value="e-mail">E-mail</option>
            					<option value="research_area">Research Area</option>
            					<option value="undergraduate_school">Undergraduate School</option>
            					<option value="gpa">GPA</option>
            				</select>
            				
            				<input type="submit" id="sort_button" value="Submit" />
            				</td>
            			</tr>
            		</table>
            	</form>
            </div>
            
         	<br/>
       	  <table border="0" cellpadding="0" cellspacing="0" id="apptable">
			<tr>
            	<th>Personal Infomation</th>
                <th>Undergraduate Infomation</th>
                <th>Graduate Infomation</th>
                <th>Application Infomation</th>
            </tr>
            <% for( int i = 0; i < apps.size(); i++ ) { %>
            	<% Application app = (Application) apps.get(i); %>
            	<% if (i%2==1) { %>
            		<tr class="odd">
            	<% }  else { %>
            		<tr class="even">
            	<% } %>
            
                      <td>
                      	<table>
                        	<tr>
                            	<td><strong>Name:</strong></td>
                                <td><%=app.getFirstName()%> <%=app.getLastName()%></td>
                            </tr>
                            <tr>
                            	<td><strong>Reviews Needed:</strong></td>
                                <td><%=app.getNumDesiredReviews()%>/5</td>
                            </tr>
                            <tr>
                            	<td><strong>Download Application:</strong></td>
                                <td><a href="<%=app.getPdfUrl()%>">Download</a></td>
                            </tr>
                            <tr>
                            	<td><strong>View Application:</strong></td>
                                <td>

                                	<form  action="ViewApplication.do" method="post">
                                		<input type="hidden" name="appID" id="appID" value="<%=app.getEmail()%>"/>
                                		<input type="submit" class="btn" value="View Application" />
                                	</form>
                                	
                                </td>
                            </tr>
                            <tr>
                            	<td><strong>Email:</strong></td>
                                <td><%=app.getEmail()%></td>
                            </tr>
                        </table>
                      </td>
                      <td>
                      	<table>
                        	<tr>
                            	<td><strong>Research Area:</strong></td>
                                <td><%=app.getResearchArea()%></td>
                            </tr>
                            <tr>
                            	<td><strong>Undergraduate School:</strong></td>
                                <td><%=app.getUgInst()%></td>
                            </tr>
                            <tr>
                            	<td><strong>Undergraduate GPA:</strong></td>
                                <td><%=app.getUgGpa()%></td>
                            </tr>
                        </table>
                      </td>
                	  <td>
                      	<table>
                        	<tr>
                            	<td><strong>GRE Scores:</strong></td>
                                <td>Quantitative: <%=app.getOfclGreQ()%> :: Analytical: <%=app.getOfclGreA()%> :: Verbal scores: <%=app.getOfclGreV()%></td>
                            </tr>
                            <tr>
                            	<td><strong>Graduate School:</strong></td>
                                <td><%=app.getGradInst()%></td>
                            </tr>
                            <tr>
                            	<td><strong>Graduate GPA:</strong></td>
                                <td><%=app.getGradGpa()%></td>
                            </tr>
                        </table>
                      </td>
                	<td>
                      	<table>
                        	
                            <tr>
                            	<td><strong>Rating:</strong></td>
                                <td><%=app.getRating1()%>, <%=app.getRating2()%>, <%=app.getRating3()%>, <%=app.getRating4()%>, <%=app.getRating5() %></td>
                            </tr>
                            <tr>
                            	<td><strong>Average Rating:</strong></td>
                                <td><%=app.getAvgRating()%>/6.0</td>
                            </tr>
                             <tr>
                            	<td><strong>Summary:</strong></td>
                                <td><% 
                                		String x = "";
                                		if(app.getSummary() != null) {
	                                		if(app.getSummary().length() > 20 ){
	                                			x = app.getSummary().substring(0, 20);%>
	                                			<%=x%>...
	                                		<%} else { %> 
	                                		<%=app.getSummary()%>
	                                		<% } %>
	                                	<%}  else { %>
	                                	<p>No Summary!</p>
	                                	<% } %>
                                </td>
                            </tr>
                        </table>
                      </td>
                  </tr>
        <% } %>
             
          </table>
        <!-- this will start the JSP include page for the bottom of the website because it will never change-->
        </div>
        
        <div id="footer">
			
        </div>
    </div>
</body>
</html>